package vn.com.vega.music.view.custom;

import vn.com.vega.chacha.R;
import vn.com.vega.music.utils.Util;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TopTabSelectView extends LinearLayout {
	private TextView leftText;
	private TextView centerText;
	private TextView rightText;

	public TopTabSelectView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.view_top_tab, this);
		leftText = (TextView) view.findViewById(R.id.tv_left);
		centerText = (TextView) view.findViewById(R.id.tv_center);
		rightText = (TextView) view.findViewById(R.id.tv_right);
	}

	public void setLeftText(String txt, View.OnClickListener click,
			boolean isSelected) {
		leftText.setText(txt);
		leftText.setOnClickListener(click);
		if (Util.checkStringIsemptyOrNull(txt)) {
			leftText.setVisibility(View.INVISIBLE);
		} else {
			leftText.setVisibility(View.VISIBLE);
			if (isSelected) {
				leftText.setBackgroundResource(R.drawable.tab_selected);
			} else {
				leftText.setBackgroundResource(R.drawable.tab_unselected);
			}
		}

	}

	public void setCenterText(String txt, View.OnClickListener click,
			boolean isSelected) {
		centerText.setText(txt);
		centerText.setOnClickListener(click);
		if (Util.checkStringIsemptyOrNull(txt)) {
			centerText.setVisibility(View.INVISIBLE);
		} else {
			centerText.setVisibility(View.VISIBLE);
			if (isSelected) {
				centerText.setBackgroundResource(R.drawable.tab_selected);
			} else {
				centerText.setBackgroundResource(R.drawable.tab_unselected);
			}
		}
	}

	public void setRightText(String txt, View.OnClickListener click,
			boolean isSelected) {
		rightText.setText(txt);
		rightText.setOnClickListener(click);
		if (Util.checkStringIsemptyOrNull(txt)) {
			rightText.setVisibility(View.INVISIBLE);
		} else {
			rightText.setVisibility(View.VISIBLE);
			if (isSelected) {
				rightText.setBackgroundResource(R.drawable.tab_selected);
			} else {
				rightText.setBackgroundResource(R.drawable.tab_unselected);
			}
		}
	}

	@Override
	public void setOnTouchListener(View.OnTouchListener listener) {
		leftText.setOnTouchListener(listener);
		centerText.setOnTouchListener(listener);
		rightText.setOnTouchListener(listener);
	}

	/*
	 * private void setTextFromXml(AttributeSet attrs) { String leftText =
	 * attrs.getAttributeValue(nameSpace, TAG_LEFT_TEXT); if (leftText != null)
	 * { this.leftText.setText(leftText); }
	 * 
	 * String centerText = attrs.getAttributeValue(nameSpace, TAG_CENTER_TEXT);
	 * if (centerText != null) { this.centerText.setText(centerText); }
	 * 
	 * String rightText = attrs.getAttributeValue(centerText, TAG_RIGHT_TEXT);
	 * if (rightText != null) { this.rightText.setText(rightText); } }
	 */

}
